﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProcCodeCreator
{
    public class Writer
    {
        public static string FilePath = "";
        public static string DALFilePath = "";
        public static string ModelFilePath = "";

        public static void SetPath(string FilePath)
        {
            DALFilePath = FilePath + @"\DAL\";
            if (Directory.Exists(DALFilePath))
            {Directory.Delete(DALFilePath,true);}
            if (!Directory.Exists(DALFilePath))
            {
                Directory.CreateDirectory(DALFilePath);
            }
             
            ModelFilePath = FilePath + @"\Model\";
            if (Directory.Exists(ModelFilePath))
            { Directory.Delete(ModelFilePath, true); }
            if (!Directory.Exists(ModelFilePath))
            {
                Directory.CreateDirectory(ModelFilePath);
            }
        }

        public static void SaveDAL(string FullFileName, string Text)
        {
            using (FileStream fs = new FileStream(DALFilePath + FullFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                fs.Seek(0, SeekOrigin.End);
                StreamWriter w = new StreamWriter(fs);
                w.Write("\r\n");
                w.Write(Text);
                w.Flush();
                w.Close();
            }
        }

        public static void SaveModel(string FullFileName, string Text)
        {
            using (FileStream fs = new FileStream(ModelFilePath + FullFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                fs.Seek(0, SeekOrigin.End);
                StreamWriter w = new StreamWriter(fs);
                w.Write("\r\n");
                w.Write(Text);
                w.Flush();
                w.Close();
            }
        }
    }
}
